<template>
  <div id="app" class="weekDetails_container ">
    <div id="demo"></div>
    <!-- <button class="next" @click="next()">查看下一篇</button> -->
  </div>

</template>
<script>
import path from '@/network'
import Pdfh5 from "pdfh5";
import "pdfh5/css/pdfh5.css";

export default {
  name: 'App',
  data () {
    return {
      pdfh5: null,
      weekList: [],
      total: 0,
      pagesize: 10,
      currentPage: 1,
      idList: [],
      currentId: this.$route.query.secondId,
      type: this.$route.query.type,
      resourcesUrl: ''
    };
  },
  mounted () {
    if (this.type == 1) {
      this.resourcesUrl = this.$route.query.resourcesUrl
      this.pdfh5 = new Pdfh5("#demo", {
        pdfurl: this.resourcesUrl,
        lazy: true
      });

      this.pdfh5.on("complete", function (status, msg, time) {
        console.log("状态：" + status + "，信息：" + msg + "，耗时：" + time + "毫秒，总页数：" + this.totalNum)
      })

    } else {
      this.getlawDetails(this.$route.query.secondId);
      this.getSecondType(this.$route.query.firstId);

    }


  },


  methods: {
    //获取详情
    getlawDetails (id) {
      this.loading = true;
      path.getlawDetails(
        id
      ).then(res => {
        if (res.success === 0) {

          this.currentId = id
          this.resourcesUrl = res.rows.resourcesUrl
          //this.resourcesUrl = 'https://cdn2.pluslegal.cn/miniapp-changdu/test1.pdf'
          this.pdfh5 = new Pdfh5("#demo", {
            pdfurl: this.resourcesUrl,
            lazy: true
          });

          this.pdfh5.on("complete", function (status, msg, time) {
            console.log("状态：" + status + "，信息：" + msg + "，耗时：" + time + "毫秒，总页数：" + this.totalNum)
          })

        }

      })
    },


    //获取二级
    getSecondType (id) {
      path.getSecondType(
        id
      ).then(res => {
        if (res.success === 0) {
          var weekId = res.rows[1].id;
          this.getLawList(weekId)
        }
      })
    },

    //获取list
    getLawList (id) {
      path.getLawList(
        this.currentPage,
        this.pagesize,
        id
      ).then(res => {
        if (res.success === 0) {
          res.rows.forEach(item => {
            this.idList.push(item.id)
          });
        }
      })
    },

    next () {
      this.pageNum = 1,
        this.idList.forEach((item, index) => {
          if (item == this.currentId) {
            if (index < this.idList.length - 1) {
              this.getlawDetails(this.idList[index + 1])
              return false;
            } else {
              this.$message({
                message: '当前是最后一篇！',
                type: 'error'
              });
            }
            return false;
          }
        });

    }

  }
}
</script>